package com.group01.community.config;

import com.group01.community.constant.Constants;
import com.group01.community.utils.AsyncFactory;
import com.group01.community.utils.ResponseResult;
import com.group01.community.utils.ResponseStatus;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LogoutSuccessHandle implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest req, HttpServletResponse resp, Authentication authentication) throws IOException, ServletException {
        String username = req.getParameter("user");

        //记录注销信息
        AsyncFactory.recordLogininfor(username,

                Constants.LOGOUT, ResponseStatus.LOGOUT_SUCCESS.getMessage());
        ResponseResult.write(resp, ResponseResult.ok("注销成功"));
    }
}
